import {
	listGoodsSpec,
	listGoodsDetail,
	listGoodsStock,
	getGoodsSpecInfo
} from '@/api/goods'
export default {
	data() {
		return {
			specType: "",
			specNameList: [],
			goodsDetailList: [],
			goodsStockList: [],
		}
	},
	methods: {
		async getGoodsSpecInfo(goodsId) {
			const data = (await getGoodsSpecInfo(goodsId)).data;
			this.specType = data.specType;
			this.specNameList = data.specNameList;
			this.goodsDetailList = data.goodsDetailList;
			this.goodsStockList = data.goodsStockList;
			let isPopupShow = true;
			// 规格只有一种，直接将该商品加入购物车
			if (this.specNameList.length == 1) {
				isPopupShow = false;
			}
			return Promise.resolve(isPopupShow);
		},
		/**
		 * 加入购物车动画
		 */
		cartBall() {
			const index = this.ballGoodsIdx;
			let cartIcon = uni
				.createSelectorQuery()
				.in(this)
				.selectAll('.cart-icon')
				.boundingClientRect((rect) => {
					// console.log("元素位置", rect)
					// console.log(index, rect[index].left, rect[index].top)
					this.$refs.cartBall[index].drop({
						x: rect[index].left,
						y: rect[index].top
					});
				})
				.exec();
		},
	}
}